#define  _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>

using namespace std;
//三指针法，三种情况分开讨论一定要用if else不要一直用if，并和或一定要注意
class Solution {
public:
    void sortColors(vector<int>& nums) {
        int n = nums.size();
        int i = 0;
        int left = -1;
        int right = n;

        while (i < right)
        {
            if (nums[i] == 0)
            {
                swap(nums[++left], nums[i++]);
            }
            else if (nums[i] == 1)
            {
                i++;
            }
            else
            {
                swap(nums[--right], nums[i]);
            }
        }


    }
};
int main()
{

    vector<int> ans = { 2,0,2,1,1,0 };
    Solution().sortColors(ans);

	return 0;
}